using System;
using System.Collections.Generic;
using System.Text;
using Barrage.GUI;
using Barrage.GUI.Elements;
using Barrage.Global;
using Spacedash.Logic.Scenario;
using Spacedash.Logic;

namespace Spacedash.Game.Subgames
{
    static class NewGameElements
    {
        public const string ExitButton = "EXIT_BUTTON";
        public const string NextButton = "NEXT_BUTTON";
        public const string PlayerNumberSelector = "PLAYERNUMBER_SELECT";
        public const string LevelSelector = "LEVEL_SELECT";
        public const string LapNumberSelector = "LAPNUMBER_SELECT";
    }
    class NewGameSection : GUISection
    {
        public override int Id
        {
            get { return (int)GameState.NewGameMenu; }
        }

        public NewGameSection(SpacedashGame parent)
            : base("NewGame", parent)
        {
            RegisterButtonEvent(NewGameElements.ExitButton, new GUIButtonHandler(ExitButtonClick));
            RegisterButtonEvent(NewGameElements.NextButton, new GUIButtonHandler(NextButtonClick));
            FillLevels();
        }

        void FillLevels()
        {
            GUISelector selector = ((GUISelector)Layout.Elements[NewGameElements.LevelSelector]);

            int i = 0;
            foreach (string name in Scenario.GetAvailableScenarios())
            {
                ((GUISelector)Layout.Elements[NewGameElements.LevelSelector]).addOption(i++, name);
            } 
        }

        public void NextButtonClick(string buttonId)
        {
            int playerNumber = ((GUINumberSelector)Layout.Elements[NewGameElements.PlayerNumberSelector]).Value;
            string scenario = ((GUISelector)Layout.Elements[NewGameElements.LevelSelector]).CurrentOptionValue;
            int lapNumber = ((GUINumberSelector)Layout.Elements[NewGameElements.LapNumberSelector]).Value;
            RaceCreationParams rcp = new RaceCreationParams(scenario, playerNumber, lapNumber);
            Parent.NextGameSection = new SelectProfileSection((SpacedashGame)Parent,rcp,0);
        }

        public void ExitButtonClick(string buttonId)
        {
            Parent.NextGameSectionId = (int)GameState.MainMenu;
        }
    }
}
